package com.new_wear.project.system.access.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.new_wear.framework.aspectj.lang.annotation.Log;
import com.new_wear.framework.aspectj.lang.enums.BusinessType;
import com.new_wear.project.system.access.domain.CstVolunteerGroupAccess;
import com.new_wear.project.system.access.service.ICstVolunteerGroupAccessService;
import com.new_wear.framework.web.controller.BaseController;
import com.new_wear.framework.web.domain.AjaxResult;
import com.new_wear.common.utils.poi.ExcelUtil;
import com.new_wear.framework.web.page.TableDataInfo;

/**
 * 志愿者 - 志愿者团体关联Controller
 * 
 * @author new_wear
 * @date 2020-01-02
 */
@Controller
@RequestMapping("/system/access")
public class CstVolunteerGroupAccessController extends BaseController
{
    private String prefix = "system/access";

    @Autowired
    private ICstVolunteerGroupAccessService cstVolunteerGroupAccessService;

    @RequiresPermissions("system:access:view")
    @GetMapping()
    public String access()
    {
        return prefix + "/access";
    }

    /**
     * 查询志愿者 - 志愿者团体关联列表
     */
    @RequiresPermissions("system:access:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(CstVolunteerGroupAccess cstVolunteerGroupAccess)
    {
        startPage();
        List<CstVolunteerGroupAccess> list = cstVolunteerGroupAccessService.selectCstVolunteerGroupAccessList(cstVolunteerGroupAccess);
        return getDataTable(list);
    }

    /**
     * 导出志愿者 - 志愿者团体关联列表
     */
    @RequiresPermissions("system:access:export")
    @Log(title = "志愿者 - 志愿者团体关联", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(CstVolunteerGroupAccess cstVolunteerGroupAccess)
    {
        List<CstVolunteerGroupAccess> list = cstVolunteerGroupAccessService.selectCstVolunteerGroupAccessList(cstVolunteerGroupAccess);
        ExcelUtil<CstVolunteerGroupAccess> util = new ExcelUtil<CstVolunteerGroupAccess>(CstVolunteerGroupAccess.class);
        return util.exportExcel(list, "access");
    }

    /**
     * 新增志愿者 - 志愿者团体关联
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存志愿者 - 志愿者团体关联
     */
    @RequiresPermissions("system:access:add")
    @Log(title = "志愿者 - 志愿者团体关联", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(CstVolunteerGroupAccess cstVolunteerGroupAccess)
    {
        return toAjax(cstVolunteerGroupAccessService.insertCstVolunteerGroupAccess(cstVolunteerGroupAccess));
    }

    /**
     * 修改志愿者 - 志愿者团体关联
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Integer id, ModelMap mmap)
    {
        CstVolunteerGroupAccess cstVolunteerGroupAccess = cstVolunteerGroupAccessService.selectCstVolunteerGroupAccessById(id);
        mmap.put("cstVolunteerGroupAccess", cstVolunteerGroupAccess);
        return prefix + "/edit";
    }

    /**
     * 修改保存志愿者 - 志愿者团体关联
     */
    @RequiresPermissions("system:access:edit")
    @Log(title = "志愿者 - 志愿者团体关联", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(CstVolunteerGroupAccess cstVolunteerGroupAccess)
    {
        return toAjax(cstVolunteerGroupAccessService.updateCstVolunteerGroupAccess(cstVolunteerGroupAccess));
    }

    /**
     * 删除志愿者 - 志愿者团体关联
     */
    @RequiresPermissions("system:access:remove")
    @Log(title = "志愿者 - 志愿者团体关联", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(cstVolunteerGroupAccessService.deleteCstVolunteerGroupAccessByIds(ids));
    }
}
